package com.qingding.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qingding.R;

import java.util.List;

import com.qingding.view.LinearItem;

/**
 * Created by zcy on 2017-12-20.
 */
//这相当于一个辅助类，但是辅助的谁暂时还不清楚
public class ItemAdapter extends ArrayAdapter {
    private int layout;
    public ItemAdapter(Context context,int resource, List<LinearItem> objects) {
        super(context, resource, objects);
        this.layout = resource;
    }

    @Override
    public View getView(int position,View convertView,ViewGroup parent) {
        LinearItem linearItem=(LinearItem) getItem(position);
        View lay_out_container;
        ViewHolder viewHolder;
        if(convertView==null) {
            viewHolder=new ViewHolder();
            lay_out_container = LayoutInflater.from(getContext()).inflate(layout, parent, false);
            viewHolder.sign = (ImageView) lay_out_container.findViewById(R.id.sign);
            viewHolder.item_name = (TextView) lay_out_container.findViewById(R.id.item_name);
        }else{
            lay_out_container=convertView;
            viewHolder=(ViewHolder) lay_out_container.getTag();
        }
        viewHolder.sign.setImageResource(linearItem.getSign());
        viewHolder.item_name.setText(linearItem.getItemName());
        return lay_out_container;
    }
    class ViewHolder{
        ImageView sign;
        TextView item_name;
    }
}
